/* 
 * @author Mabel Xu
 */

import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.grid.Location;

import java.awt.Color;
import java.util.ArrayList;

public class BlusterCritter extends Critter
{
	private int courage;
	private static final double COLOR_FACTOR = 0.05;
	
	public BlusterCritter(int c)
	{
		super();
		courage = c;
	}
	
	public ArrayList<Actor> getActors()
	{
		ArrayList<Actor> neighbors = new ArrayList<Actor>();
		for (int i = this.getLocation().getRow() - 1; i <= this.getLocation().getRow() + 1; i++)
		{
			for (int j = this.getLocation().getCol() - 1; j <= this.getLocation().getCol() + 1; j++)
			{
				if (this.getGrid().isValid(new Location(i, j)))
					if (this.getGrid().get(new Location(i, j)) != null)
						neighbors.add(this.getGrid().get(new Location(i, j)));	
			}
		}
		return neighbors;
	}
	
	public void processActors(ArrayList<Actor> actors)
	{
		int count = 0;
		for (Actor a : actors)
			if (a instanceof Critter)
				count++;
		if (count > courage)
			this.setColor(
        			new Color(
        				(int)(this.getColor().getRed() * (1 - COLOR_FACTOR)),
        				(int)(this.getColor().getGreen() * (1 - COLOR_FACTOR)),
        				(int)(this.getColor().getBlue() * (1 - COLOR_FACTOR))
        			));
		else if (count < courage)
			this.setColor(
        			new Color(
        				(int)(this.getColor().getRed() * (1 + COLOR_FACTOR)),
        				(int)(this.getColor().getGreen() * (1 + COLOR_FACTOR)),
        				(int)(this.getColor().getBlue() * (1 + COLOR_FACTOR))
        			));
	}
}
